package com.ruoyi.peizhen.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peizhen.domain.PzHospitalHospital;
import com.ruoyi.peizhen.service.IPzHospitalHospitalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医院Controller
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@Controller
@RequestMapping("/peizhen/hospital")
public class PzHospitalHospitalController extends BaseController
{
    private String prefix = "peizhen/hospital";

    @Autowired
    private IPzHospitalHospitalService pzHospitalHospitalService;

    @RequiresPermissions("peizhen:hospital:view")
    @GetMapping()
    public String hospital()
    {
        return prefix + "/hospital";
    }

    /**
     * 查询医院列表
     */
    @RequiresPermissions("peizhen:hospital:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PzHospitalHospital pzHospitalHospital)
    {
        startPage();
        List<PzHospitalHospital> list = pzHospitalHospitalService.selectPzHospitalHospitalList(pzHospitalHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院列表
     */
    @RequiresPermissions("peizhen:hospital:export")
    @Log(title = "医院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PzHospitalHospital pzHospitalHospital)
    {
        List<PzHospitalHospital> list = pzHospitalHospitalService.selectPzHospitalHospitalList(pzHospitalHospital);
        ExcelUtil<PzHospitalHospital> util = new ExcelUtil<PzHospitalHospital>(PzHospitalHospital.class);
        return util.exportExcel(list, "医院数据");
    }

    /**
     * 新增医院
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医院
     */
    @RequiresPermissions("peizhen:hospital:add")
    @Log(title = "医院", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PzHospitalHospital pzHospitalHospital)
    {
        return toAjax(pzHospitalHospitalService.insertPzHospitalHospital(pzHospitalHospital));
    }

    /**
     * 修改医院
     */
    @RequiresPermissions("peizhen:hospital:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PzHospitalHospital pzHospitalHospital = pzHospitalHospitalService.selectPzHospitalHospitalById(id);
        mmap.put("pzHospitalHospital", pzHospitalHospital);
        return prefix + "/edit";
    }

    /**
     * 修改保存医院
     */
    @RequiresPermissions("peizhen:hospital:edit")
    @Log(title = "医院", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PzHospitalHospital pzHospitalHospital)
    {
        return toAjax(pzHospitalHospitalService.updatePzHospitalHospital(pzHospitalHospital));
    }

    /**
     * 删除医院
     */
    @RequiresPermissions("peizhen:hospital:remove")
    @Log(title = "医院", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pzHospitalHospitalService.deletePzHospitalHospitalByIds(ids));
    }
}
